home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / exec / makefunctions.c < prev    next >
C/C++ Source or Header  |  1996-09-12  |  3KB  |  113 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: makefunctions.c,v 1.4 1996/08/13 13:56:03 digulla Exp $
  4.     $Log: makefunctions.c,v $
  5.     Revision 1.4  1996/08/13 13:56:03  digulla
  6.     Replaced __AROS_LA by __AROS_LHA
  7.     Replaced some __AROS_LH*I by __AROS_LH*
  8.     Sorted and added includes
  9.  
  10.     Revision 1.3  1996/08/01 17:41:13  digulla
  11.     Added standard header for all files
  12.  
  13.     Desc:
  14.     Lang: english
  15. */
  16. #include <exec/execbase.h>
  17. #include <aros/libcall.h>
  18. #include "machine.h"
  19.  
  20. /*****************************************************************************
  21.  
  22.     NAME */
  23.     #include <clib/exec_protos.h>
  24.  
  25.     __AROS_LH3(ULONG, MakeFunctions,
  26.  
  27. /*  SYNOPSIS */
  28.     __AROS_LHA(APTR, target,        A0),
  29.     __AROS_LHA(APTR, functionArray, A1),
  30.     __AROS_LHA(APTR, funcDispBase,  A2),
  31.  
  32. /*  LOCATION */
  33.     struct ExecBase *, SysBase, 15, Exec)
  34.  
  35. /*  FUNCTION
  36.     Creates the jumptable for a shared library and flushes the processor's
  37.     instruction cache. Does not checksum the library.
  38.  
  39.     INPUTS
  40.     target          - The highest byte +1 of the jumptable. Typically
  41.             this is the library's base address.
  42.     functionArray - Pointer to either an array of function pointers or
  43.             an array of WORD displacements to a given location
  44.             in memory. A value of -1 terminates the array in both
  45.             cases.
  46.     funcDispBase  - The base location for WORD displacements or NULL
  47.             for function pointers.
  48.  
  49.     RESULT
  50.     Size of the jumptable.
  51.  
  52.     NOTES
  53.  
  54.     EXAMPLE
  55.  
  56.     BUGS
  57.  
  58.     SEE ALSO
  59.  
  60.     INTERNALS
  61.  
  62.     HISTORY
  63.  
  64. ******************************************************************************/
  65. {
  66.     __AROS_FUNC_INIT
  67.  
  68.     /* Cast for easier access */
  69.     struct JumpVec *jv=(struct JumpVec *)target;
  70.  
  71.     if(funcDispBase!=NULL)
  72.     {
  73.     /* If FuncDispBase is non-NULL it's an array of relative offsets */
  74.     WORD *fp=(WORD *)functionArray;
  75.  
  76.     /* -1 terminates the array */
  77.     while(*fp!=-1)
  78.     {
  79.         /* Decrement vector pointer by one and install vector */
  80.         jv--;
  81.         SET_JMP(jv);
  82.         SET_VEC(jv,(BYTE *)funcDispBase+*fp);
  83.  
  84.         /* Use next array entry */
  85.         fp++;
  86.     }
  87.     }else
  88.     {
  89.     /* If FuncDispBase is NULL it's an array of function pointers */
  90.     void **fp=(void **)functionArray;
  91.  
  92.     /* -1 terminates the array */
  93.     while(*fp!=(void *)-1)
  94.     {
  95.         /* Decrement vector pointer by one and install vector */
  96.         jv--;
  97.         SET_JMP(jv);
  98.         SET_VEC(jv,*fp);
  99.  
  100.         /* Use next array entry */
  101.         fp++;
  102.     }
  103.     }
  104.  
  105.     /* Clear instruction cache for the whole jumptable */
  106.     CacheClearE(jv,(BYTE *)funcDispBase-(BYTE *)jv,CACRF_ClearI);
  107.  
  108.     /* Return size of jumptable */
  109.     return (BYTE *)funcDispBase-(BYTE *)jv;
  110.     __AROS_FUNC_EXIT
  111. } /* MakeFunctions */
  112.  
  113.